package com.mohan.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.mohan.bean.ArticleListInfo;
import com.mohan.dao.ArticleDao;
import com.mohan.dao.CommentDao;
import com.mohan.dao.ContentDao;
import com.mohan.dao.ImgDao;
import com.mohan.dao.ReplyDao;
import com.mohan.pojo.Article;
import com.mohan.pojo.Comment;
import com.mohan.pojo.Content;
import com.mohan.pojo.Img;
import com.mohan.pojo.Reply;
import com.mohan.req.ChgArticleClassReq;
import com.mohan.req.ChgExamineReq;
import com.mohan.req.ChgIsOpenReq;
import com.mohan.req.ChgRecommendReq;
import com.mohan.req.ChgStatusReq;
import com.mohan.service.ArticleService;

@Service("articleService") 
public class ArticleServiceImpl implements ArticleService{
	@Resource
    private ArticleDao articleDao;
	
	@Resource
    private ContentDao contentDao;
	
	@Resource
    private CommentDao commentDao;
	
	@Resource
    private ImgDao imgDao;
	
	@Resource
    private ReplyDao replyDao;

	/**
	 * 插入一篇文章
	 */
	@Override
	public void insertOneArticle(Article article) throws Exception {
		// TODO Auto-generated method stub
		this.articleDao.insertArticle(article);
	}
	/**
	 * 获取刚刚插入的文章的id
	 */
	@Override
	public int getLastArticleId() throws Exception {
		// TODO Auto-generated method stub
		return this.articleDao.selectaLastArticleId();
	}
	/**
	 * 获取所有文章
	 */
	@Override
	public List<Article> getArticles() throws Exception {
		// TODO Auto-generated method stub
		return this.articleDao.selectArticles(); 
	}
	/**
	 * 更新文章表里面段落id数组
	 */
	@Override
	public void updateContentIds(Article article) throws Exception {
		// TODO Auto-generated method stub
		this.articleDao.updteContentIds(article);
	}
	/**
	 * 获取文章列表
	 */
	@Override
	public List<Article> getArticleList(String userid) throws Exception {
		// TODO Auto-generated method stub
		return this.articleDao.selectArticleListForUserId(userid);
	}
	/**
	 * 通过文章id获取文章内容
	 */
	@Override
	public Article getArticle(int articleId) throws Exception {
		// TODO Auto-generated method stub
		return this.articleDao.selectArticleByArticleId(articleId);
	}
	/**
	 * 通过文章id删除文章
	 */
	@Override
	public void deleteArticle(int articleId) throws Exception{
		this.articleDao.deleteArticle(articleId);
	}
	
	/**
	 * 文章更新
	 */
	@Override
	public void updateArticleByArticleId(Article article) throws Exception{
		this.articleDao.updateArticleByArticleId(article);
	}
	
	/**
	 * 根据用户id获取用户的文章列表
	 */
	@Override
	public Integer getCountByUserId(String userId) throws Exception{
		return this.articleDao.selectRecordSizeByUserId(userId);
	}
	
	/**
	 * 管理员获取用户文章列表,可以获取删除的文章
	 */
	@Override
	public List<Article> getArticleListByPageM(ArticleListInfo listInfo) throws Exception{
		return this.articleDao.selectRecordByPageM(listInfo);
	}
	
	/**
	 * 自己获取用户文章列表,不可以获取删除的文章
	 */
	@Override
	public List<Article> getArticleListByPageS(ArticleListInfo listInfo) throws Exception{
		return this.articleDao.selectRecordByPageS(listInfo);
	}
	
	/**
	 * 其他获取用户文章列表,不可以获取删除的文章
	 */
	@Override
	public List<Article> getArticleListByPageO(ArticleListInfo listInfo) throws Exception{
		return this.articleDao.selectRecordByPageO(listInfo);
	}
	
	/**
	 * 更改文章的状态
	 */
	@Override
	public void setArticleStatus(ChgStatusReq statusReq) throws Exception{
		this.articleDao.updateArticleStatus(statusReq);
	}
	
	/**
	 * 更改文章的审核进度
	 */
	@Override
	public void setArticleExamine(ChgExamineReq examineReq)throws Exception{
		this.articleDao.updateArticleExamine(examineReq);
	}
	
	/**
	 * 更改文章的推荐
	 */
	@Override
	public void setArticleRecommend(ChgRecommendReq recommendReq) throws Exception{
		this.articleDao.updateArticleRecommend(recommendReq);
	}
	
	/**
	 * 更改文章的公开状态
	 */
	@Override
	public void setArticleIsOpen(ChgIsOpenReq isOpenReq) throws Exception{
		this.articleDao.updateArticleIsOpen(isOpenReq);
	}
	
	/**
	 * 更改文章的类别
	 */
	@Override
	public void setArticleClass(ChgArticleClassReq classReq) throws Exception{
		this.articleDao.updateArticleClass(classReq);
	}
	
	/**
	 * 插入一个段落
	 */
	@Override
	public void insertContent(Content content) throws Exception {
		// TODO Auto-generated method stub
		this.contentDao.insertContent(content);
	}
	/**
	 * 获取刚刚插入段落的id
	 */
	@Override
	public int getLastContentId() throws Exception {
		// TODO Auto-generated method stub
		return this.contentDao.selectLastContentId();
	}
	
	/**
	 * 更新content
	 */
	@Override
	public void updateContent(Content content) throws Exception{
		this.contentDao.updteContentByContentId(content);
	}
	
	/**
	 * 删除content
	 */
	@Override
	public void deleteContent(int contentId) throws Exception{
		this.contentDao.deleteContentByContentId(contentId);
	}
	
	/**
	 * 更新段落的插图id数组
	 */
	@Override
	public void updateImgIds(Content content) throws Exception {
		// TODO Auto-generated method stub
		this.contentDao.updteImgIds(content);
	}
	/**
	 * 根据文章id获取文章下所有段落
	 */
	@Override
	public List<Content> getContents(int articleid) throws Exception {
		// TODO Auto-generated method stub
		return this.contentDao.selectContentsForArticleId(articleid);
	}
	
	/**
	 * 根据contentId获取内容
	 */
	@Override
	public Content getContentByContentId(int contentId) throws Exception{
		return this.contentDao.selectContentByContentId(contentId);
	}
	
	/**
	 * 插入一个图片
	 */
	@Override
	public void insertOneImg(Img img) throws Exception {
		// TODO Auto-generated method stub
		this.imgDao.insertImg(img);
	}	
	/**
	 * 获取刚刚插入图片的id
	 */
	@Override
	public int getLastImgId() throws Exception {
		// TODO Auto-generated method stub
		return this.imgDao.selectLastImgId();
	}
	/**
	 * 根据段落id获取段落下的插图
	 */
	@Override
	public List<Img> getImgs(int contentid) throws Exception {
		// TODO Auto-generated method stub
		return this.imgDao.selectImgsForContentId(contentid);
	}
	
	/**
	 * 根据imgId获取图片信息
	 */
	@Override
	public Img getImgByImgId(int imgId) throws Exception {
		// TODO Auto-generated method stub
		return this.imgDao.selectImgByImgId(imgId);
	}
	
	/**
	 * 根据图片id删除图片
	 */
	@Override
	public void deleteImgByImgId(int imgId) throws Exception{
		this.imgDao.deleteByImgId(imgId);
	}
	
	/**
	 * 更新图片
	 */
	@Override
	public void updateImgByImgId(Img img) throws Exception{
		this.imgDao.updateImgByImgId(img);
	}
	
	/**
	 * 根据文章id获取文章下所有评论
	 */
	@Override
	public List<Comment> getComments(int articleid) throws Exception {
		// TODO Auto-generated method stub
		return this.commentDao.selectCommentsForArticleId(articleid);
	}
	/**
	 * 根据评论id获取该评论下的所有回复
	 */
	@Override
	public List<Reply> getReplys(int commentid) throws Exception {
		// TODO Auto-generated method stub
		return this.replyDao.selectReplysForCommentId(commentid);
	}
	
	/**
	 * 根据文章id获取文章所属用户id的角色
	 */
	@Override
	public int getRoleByArticleId(int articleId) throws Exception {
		// TODO Auto-generated method stub
		return this.articleDao.selectRoleByArticleId(articleId);
	}
	
	
}
